﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Zhaoxi.FactoryDeviceSystem.UControls
{
    public partial class UCDevSwitch : UserControl
    {
        public UCDevSwitch()
        {
            InitializeComponent();
        }

        //DeviceNo DeviceName  CanOpen  CanClose   CurState  事件：OpenEvent   CloseEvent

        #region 属性
        //设备编号
        public int DeviceNo { get; set; }
        //设备名称
        public string DeviceName
        {
            get { return lblDevName.Text; }
            set
            {
                lblDevName.Text = value;
            }
        }

        //是否可启动设备
        public bool CanOpen
        {
            get { return btnOpen.Enabled; }
            set
            {
                btnOpen.Enabled = value ;
                if(value==false)
                {
                    btnOpen.BgColor = Color.Gray;
                    btnOpen.ForeColor = Color.LightGray;
                }
                else
                {
                    btnOpen.BgColor = Color.Green;
                    btnOpen.ForeColor = Color.White;
                }
            }
        }

        /// <summary>
        /// 是否可停止设备
        /// </summary>
        public bool CanClose
        {
            get { return btnClose.Enabled; }
            set
            {
                btnClose.Enabled = value;
                if (value == false)
                {
                    btnClose.BgColor = Color.Gray;
                    btnClose.ForeColor = Color.LightGray;
                }
                else
                {
                    btnClose.BgColor = Color.Brown;
                    btnClose.ForeColor = Color.White;
                }
            }
        }
        //当前的设备的状态
        public bool CurState { get; set; }
        #endregion

        #region 事件
        public event EventHandler StartEvent;//启动事件
        public event EventHandler StopEvent;//停止事件
        #endregion

        //启动设备
        private void btnOpen_Click(object sender, EventArgs e)
        {
            StartEvent?.Invoke(this, EventArgs.Empty);
        }

        //停止设备
        private void btnClose_Click(object sender, EventArgs e)
        {
            StopEvent?.Invoke(this, EventArgs.Empty);
        }

        private void lblDevName_Click(object sender, EventArgs e)
        {

        }

        private void UCDevSwitch_Load(object sender, EventArgs e)
        {

        }
    }
}
